package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/member")
@Api(tags = "手机验证码登录")
public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 手机验证码登录
     * @param order
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("手机验证码登录")
    public Result login(@RequestBody Order order) {
        boolean flag = memberService.login(order.getValidateCode(), order.getTelephone());
        if (flag) {
            return new Result(true, "验证码输入成功",null);
        } else {
            return new Result(false, MessageConstant.VALIDATECODE_ERROR,null);
        }
    }
}
